package de.tudarmstadt.ukp.wikisniffer.userstudy.evaluation;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import de.tudarmstadt.ukp.wikisniffer.userstudy.datastore.ResultStore.Action;

public class Evaluator {
	
	private ArrayList<VpEvaluator> personalResults;

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		Evaluator evaluator = new Evaluator();
		
		evaluator.doEvaluation();
		
		evaluator.outputSummary(new File("resultSummary.tsv"), "\t");
		

	}
	
	private void doEvaluation() throws IOException{
		String path = "results";
		personalResults = new ArrayList<VpEvaluator>();

		for(File file : new File(path).listFiles())
		{
			String[] fileNameSplitted = file.getName().split("\\.");
		 	String fileExtension = "";
		 	String fileNameWithoutExtension = fileNameSplitted[0];
		 	
		 	if(fileNameSplitted.length > 1)
		 		fileExtension = fileNameSplitted[fileNameSplitted.length - 1];
		 	
		 	
		 	
		 	if(fileExtension.equals("dat") && !fileNameWithoutExtension.equals(""))
		 		personalResults.add(new VpEvaluator(file));
		}

	}
	
	private void outputSummary(File file, String seperator) throws IOException{
		BufferedWriter writer = new BufferedWriter(new FileWriter(file));
		for(VpEvaluator oneVp : personalResults){
			writer.write(oneVp.getOutputString(seperator));
			writer.write("\n");
		}
		writer.close();
	}
	
}
	
